package xyz.robinbingo.dailybill.web.controller;

import cn.hutool.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import xyz.robinbingo.dailybill.service.BillDetailService;
import xyz.robinbingo.dailybill.web.rsp.Rsp;

/**
 * 首页Controller
 *
 * @author Robin
 * @date 2019/01/09 10:44
 **/
@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private BillDetailService billDetailService;

    @GetMapping("/sum")
    public Rsp sum(@RequestParam(required = false) String date) {
        Rsp rsp = new Rsp();
        JSONObject total = billDetailService.sum(date);
        rsp.putAll(total);
        return rsp;
    }

    @GetMapping("/list")
    public Rsp billList(@RequestParam(required = false) String date) {
        Rsp rsp = new Rsp();
        rsp.put("billList", billDetailService.billList(date));
        return rsp;
    }
}
